/*
 * Main.fx
 *
 * Created on 23.09.2009, 20:06:22
 */

package javafx179labs.dergunov.lab4;

import javafx.animation.transition.*;
import javafx.scene.effect.Glow;
import javafx.scene.input.MouseEvent;
import javafx.animation.Timeline;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.animation.KeyFrame;
import javafx.animation.transition.*;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.*;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;

//***Пробный вариант***

var myPlayer = MediaPlayer {
    autoPlay: false
    media: Media { source: "{__DIR__}02_-_Koh_Otani_-_Free_Bird.mp3"}
}

var mediaView: MediaView = MediaView {
    mediaPlayer: myPlayer
}

var glowLevel = 0.3;
var glow = Glow {
    level: bind glowLevel
}

var glowLevel_logo = 0.7;
var glow_logotype = Glow {
    level: bind glowLevel_logo
}

var bkgrnd = ImageView
{
    image: Image { url: "{__DIR__}StageBig1.jpg" }
    x: 0
    y: 0
}

/*var maidens = ImageView
{
    image: Image { url: "{__DIR__}maidens.jpg" }
    x: 0
    y: 780
}*/

var suigintou: ImageView= ImageView {
    x:270
    y:490
    image: Image {url: "{__DIR__}suigintou.png"}
   onMouseClicked: function( e: MouseEvent ):Void {
       timeline_suigintou_delete.playFromStart();
   }
 }

var rotTransition = RotateTransition {
    duration: 1.2s
    node: suigintou
    byAngle: 3
    repeatCount:100
    autoReverse: true
}

var shinku: ImageView= ImageView {
    x:460
    y:640
    image: Image {url: "{__DIR__}shinku.png"}
  onMouseClicked: function( e: MouseEvent ):Void {
       timeline_shinku_delete.playFromStart();
  }
}

var rotTransition2 = RotateTransition {
    duration: 1.8s
    node: shinku
    byAngle: 3
    repeatCount:66
    autoReverse: true
}

var hina: ImageView= ImageView {
    x:460
    y:490
    image: Image {url: "{__DIR__}hina.png"}
  onMouseClicked: function( e: MouseEvent ):Void {
       timeline_hina_delete.playFromStart();
  }
}

var rotTransition6 = RotateTransition {
    duration: 1.8s
    node: hina
    byAngle: 3
    repeatCount:-66
    autoReverse: true
}

var suiseiseki: ImageView= ImageView {
    x:650
    y:490
    image: Image {url: "{__DIR__}suiseiseki.png"}
   onMouseClicked: function( e: MouseEvent ):Void {
       timeline_suiseiseki_delete.playFromStart();
  }
 }



var rotTransition3 = RotateTransition {
    duration: 1.2s
    node: suiseiseki
    byAngle: -3
    repeatCount:100
    autoReverse: true
}

 var kanaria: ImageView= ImageView {
    x:365
    y:470
    image: Image {url: "{__DIR__}kanaria.png"}
   onMouseClicked: function( e: MouseEvent ):Void {
       timeline_kanaria_delete.playFromStart();
  }
 }

var rotTransition4 = RotateTransition {
    duration: 0.9s
    node: kanaria
    byAngle: 3
    repeatCount:100
    autoReverse: true
}

 var souseiseki: ImageView= ImageView {
    x:555
    y:470
    image: Image {url: "{__DIR__}souseiseki.png"}
   onMouseClicked: function( e: MouseEvent ):Void {
       timeline_souseiseki_delete.playFromStart();
  }
 }

var rotTransition5 = RotateTransition {
    duration: 0.9s
    node: souseiseki
    byAngle: -3
    repeatCount:100
    autoReverse: true
}

var kirakishou: ImageView= ImageView {
    x:790
    y:555
    image: Image {url: "{__DIR__}kirakishou.png"}
   onMouseClicked: function( e: MouseEvent ):Void {
       timeline_kirakishou_delete.playFromStart();
  }
 }

var rotTransition7 = RotateTransition {
    duration: 0.9s
    node: kirakishou
    byAngle: -3
    repeatCount:100
    autoReverse: true
}

var barasuishou: ImageView= ImageView {
    x:140
    y:555
    image: Image {url: "{__DIR__}barasuishou.png"}
   onMouseClicked: function( e: MouseEvent ):Void {
       timeline_barasuishou_delete.playFromStart();
  }
 }

var rotTransition8 = RotateTransition {
    duration: 0.9s
    node: barasuishou
    byAngle: -3
    repeatCount:100
    autoReverse: true
}

var logo: ImageView= ImageView {
    x:10
    y:90
    image: Image {url: "{__DIR__}logo.gif"}
    onMouseClicked: function( e: MouseEvent ):Void {
        logo_glow.playFromStart();
        rotTransition.play();
        rotTransition2.play();
        rotTransition3.play();
        rotTransition4.play();
        rotTransition5.play();
        rotTransition6.play();
        rotTransition7.play();
        rotTransition8.play();
        timeline.playFromStart();
        timeline_left_leg.playFromStart();
        timeline_right_leg.playFromStart();
        myPlayer.play();
    }
}

/*var logo_pause: ImageView= ImageView {
    x:10
    y:90
    image: Image {url: "{__DIR__}logo.gif"}
    onKeyTyped: function( e: KeyEvent ):Void {
        logo_blow.pause();
        rotTransition.pause();
        rotTransition2.pause();
        rotTransition3.pause();
        rotTransition4.pause();
        rotTransition5.pause();
        rotTransition6.pause();
        timeline.pause();
        timeline_left_leg.pause();
        timeline_right_leg.pause();
    }
}*/
//********************************



var kun_kun = ImageView
{
    image: Image { url: "{__DIR__}kun-kun.png" }
    x: 180
    y: 425
    }

var left_leg = ImageView
{
    image: Image { url: "{__DIR__}left_leg.png" }
    x: 175
    y: 443
    }

var right_leg = ImageView
{
    image: Image { url: "{__DIR__}right_leg.png" }
    x: 185
    y: 439
    }

 var logo_glow = Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames : [

                             KeyFrame {
            time : 0s
           action: function() {logo.effect = glow;}
       }
      ]
    }

   var timeline_shinku_delete = Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames : [

                             KeyFrame {
            time : 0.5s
           action: function() {shinku.effect = glow_logotype;}
       }
                              KeyFrame {
            time : 2s
            action: function() {delete shinku from Rozen_Maiden_Dance.scene.content}
       }
      ]
    }

      var timeline_hina_delete = Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames : [

                             KeyFrame {
            time : 0.5s
           action: function() {hina.effect = glow;}
       }
                              KeyFrame {
            time : 2s
            action: function() {delete hina from Rozen_Maiden_Dance.scene.content}
       }
      ]
    }

  var timeline_souseiseki_delete = Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames : [

                             KeyFrame {
            time : 0.5s
           action: function() {souseiseki.effect = glow;}
       }
                              KeyFrame {
            time : 2s
            action: function() {delete souseiseki from Rozen_Maiden_Dance.scene.content}
       }
      ]
    }

    var timeline_suiseiseki_delete = Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames : [

                             KeyFrame {
            time : 0.5s
           action: function() {suiseiseki.effect = glow;}
       }
                              KeyFrame {
            time : 2s
            action: function() {delete suiseiseki from Rozen_Maiden_Dance.scene.content}
       }
      ]
    }

        var timeline_suigintou_delete = Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames : [

                             KeyFrame {
            time : 0.5s
           action: function() {suigintou.effect = glow;}
       }
                              KeyFrame {
            time : 2s
            action: function() {delete suigintou from Rozen_Maiden_Dance.scene.content}
       }
      ]
    }

   var timeline_kanaria_delete = Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames : [

                             KeyFrame {
            time : 0.5s
           action: function() {kanaria.effect = glow;}
       }
                              KeyFrame {
            time : 2s
            action: function() {delete kanaria from Rozen_Maiden_Dance.scene.content}
       }
      ]
    }

       var timeline_barasuishou_delete = Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames : [

                             KeyFrame {
            time : 0.5s
           action: function() {barasuishou.effect = glow;}
       }
                              KeyFrame {
            time : 2s
            action: function() {delete barasuishou from Rozen_Maiden_Dance.scene.content}
       }
      ]
    }

       var timeline_kirakishou_delete = Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames : [

                             KeyFrame {
            time : 0.5s
           action: function() {kirakishou.effect = glow;}
       }
                              KeyFrame {
            time : 2s
            action: function() {delete kirakishou from Rozen_Maiden_Dance.scene.content}
       }
      ]
    }


var timeline_left_leg = Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames : [

                              KeyFrame {
            time : 0s
            values : [
               left_leg.x => 175
               ]
       }
                              KeyFrame {
            time : 1s
            values : [
               left_leg.x => 183+63.7
               ]
       }

                              KeyFrame {
            time : 2s
            values : [
               left_leg.x => 175+63.7*2
               ]
       }
                              KeyFrame {
            time : 3s
            values : [
               left_leg.x => 183+63.7*3
               ]
       }

      KeyFrame {
            time : 4s
            values : [
               left_leg.x => 175+63.7*4
               ]
       }
                              KeyFrame {
            time : 5s
            values : [
               left_leg.x => 183+63.7*5
               ]
       }

        KeyFrame {
            time : 6s
            values : [
               left_leg.x => 175+63.7*6
               ]
       }
                              KeyFrame {
            time : 7s
            values : [
               left_leg.x => 183+63.7*7
               ]
       }

        KeyFrame {
            time : 8s
            values : [
               left_leg.x => 175+63.7*8
               ]
       }
                              KeyFrame {
            time : 9s
            values : [
               left_leg.x => 183+63.7*9
               ]
       }

       KeyFrame {
            time : 10s
            values : [
               left_leg.x => 175+63.7*10
               ]
       }

       KeyFrame {
            time : 10.00000000001s
            values : [
               left_leg.x => -50
               ]
       }

                                     KeyFrame {
            time : 11s
            values : [
               left_leg.x => -40
               ]
       }

                              KeyFrame {
            time : 12s
            values : [
               left_leg.x => -30
               ]
       }
                              KeyFrame {
            time : 12.00000000001s
            values : [
               left_leg.x => 175
               ]
       }

    ]
  }

  var timeline_right_leg = Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames : [

                              KeyFrame {
            time : 0s
            values : [
               right_leg.x => 185
               ]
       }
                              KeyFrame {
            time : 1s
            values : [
               right_leg.x => 177+63.7
               ]
       }

                              KeyFrame {
            time : 2s
            values : [
               right_leg.x => 185+63.7*2
               ]
       }
                              KeyFrame {
            time : 3s
            values : [
               right_leg.x => 177+63.7*3
               ]
       }

        KeyFrame {
            time : 4s
            values : [
               right_leg.x => 185+63.7*4
               ]
       }
                              KeyFrame {
            time : 5s
            values : [
               right_leg.x => 177+63.7*5
               ]
       }

        KeyFrame {
            time : 6s
            values : [
               right_leg.x => 185+63.7*6
               ]
       }
                              KeyFrame {
            time : 7s
            values : [
               right_leg.x => 177+63.7*7
               ]
       }

        KeyFrame {
            time : 8s
            values : [
               right_leg.x => 185+63.7*8
               ]
       }
                              KeyFrame {
            time : 9s
            values : [
               right_leg.x => 177+63.7*9
               ]
       }

                              KeyFrame {
            time : 10s
            values : [
               right_leg.x => 185+63.7*10
               ]
       }

       KeyFrame {
            time : 10.00000000001s
            values : [
               right_leg.x => -50
               ]
       }

                              KeyFrame {
            time : 11s
            values : [
               right_leg.x => -40
               ]
       }

                              KeyFrame {
            time : 12s
            values : [
               right_leg.x => -30
               ]
       }
                              KeyFrame {
            time : 12.00000000001s
            values : [
               right_leg.x => 185
               ]
       }

     ]
  }

var timeline = Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames : [

                              KeyFrame {
            time : 0s
            values : [
               kun_kun.x => 180
               ]
       }

                              KeyFrame {
            time : 1s
            values : [
               kun_kun.x =>  180+63.7
               ]
       }
                              KeyFrame {
            time : 2s
            values : [
               kun_kun.x =>  180+63.7*2
               ]
       }

                              KeyFrame {
            time : 3s
            values : [
               kun_kun.x =>  180+63.7*3
               ]
       }


                              KeyFrame {
            time : 4s
            values : [
               kun_kun.x =>  180+63.7*4
               ]
       }


                              KeyFrame {
            time : 5s
            values : [
               kun_kun.x =>  180+63.7*5
               ]
       }


                              KeyFrame {
            time : 6s
            values : [
               kun_kun.x =>  180+63.7*6
               ]
       }


                              KeyFrame {
            time : 7s
            values : [
               kun_kun.x =>  180+63.7*7
               ]
       }


                              KeyFrame {
            time : 8s
            values : [
               kun_kun.x =>  180+63.7*8
               ]
       }


                              KeyFrame {
            time : 9s
            values : [
               kun_kun.x =>  180+63.7*9
               ]
       }

       KeyFrame {
            time : 10s
            values : [
               kun_kun.x =>  180+63.7*10
               ]
       }

                              KeyFrame {
            time : 10.00000000001s
            values : [
               kun_kun.x => -50
               ]
       }

                              KeyFrame {
            time : 11s
            values : [
               kun_kun.x => -40
               ]
       }

                              KeyFrame {
            time : 12s
            values : [
               kun_kun.x => -30
               ]
       }
                              KeyFrame {
            time : 12.00000000001s
            values : [
               kun_kun.x => 180
               ]
       }

        ]
      }

 //*********************************************************

var Rozen_Maiden_Dance:Stage = Stage {
    title: "Rozen Maiden"
    scene: Scene {
        width: 1024
        height: 768
        content: [
            mediaView,
            bkgrnd,
            //maidens,
            logo,
            //logo_pause,
            suigintou,
            shinku,
            hina,
            suiseiseki,
            kanaria,
            souseiseki,
            kirakishou,
            barasuishou,
            kun_kun,
            left_leg,
            right_leg,
        ]
    }
}